home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 12, No. 02 (1991-02)(MindCraft Publishing)(Side A).zip / Nibble Volume 12, No. 02 (1991-02)(MindCraft Publishing)(Side A).po / SUPERTRACE.S < prev   
Text File  |  1996-12-24  |  41KB  |  757 lines

  1.  
  2.                   KEEP  SUPERTRACE               Name the binary file
  3.                   SYMBOL OFF                     Symbol listing off
  4.                   65816 OFF                      Include these if using
  5.                   65C02 OFF                      Orca/M-GS
  6.                   ORG   $2000
  7. MAIN          START
  8. ****************************************************************
  9. *  SUPERTRACE Source Code
  10. *  by Gary Ash
  11. *  Copyright 1991 by
  12. *  MindCraft Publishing Corp.
  13. *  Concord, MA  01742
  14. *  ORCA/M Macro Assembler
  15. ****************************************************************
  16. *
  17. TVAR          GEQU  $00                      Trace variable flag
  18. TRAP          GEQU  $01                      Trap number storage
  19. LASTLN      GEQU  $02                      Last line exucuted
  20. CH              GEQU  $24                      Cursor horizontal
  21. CV              GEQU  $25                      Cursor vertical
  22. PROMPT      GEQU  $33                      System's prompt char
  23. CSW            GEQU  $36                      Char output vector
  24. KSW            GEQU  $38                      Char input vector
  25. MOVST        GEQU  $3C                      Start of block
  26. MOVEND      GEQU  $3E                      End of block
  27. MOVDST      GEQU  $42                      Destination
  28. HIMEM        GEQU  $73                      Applesoft HIMEM
  29. CURLIN      GEQU  $75                      Current line number
  30. FAC            GEQU  $9D                      Floating pnt accum
  31. DSCTMP      GEQU  $9D                      Keyword table pointer
  32. TXTPTR      GEQU  $B8                      Program text pointer
  33. POINT        GEQU  $B1                      CHRGET patch point
  34. REENTRY    GEQU  $B7                      CHRGET re-entry point
  35. SPDBYTE    GEQU  $F1                      Applesoft output speed
  36. STACKPTR  GEQU  $F8                      Applesoft stack pointer
  37. TEMP          GEQU  $FA                      Temporary storage
  38. YREG          GEQU  $FF                      Save for (Y)
  39.  
  40. INBUF        GEQU  $200                     Keyboard input buffer
  41. WARMST      GEQU  $3D0                     System warm start entry
  42. DOSHOOK    GEQU  $3EA                     Hookup DOS
  43. SOFTEV      GEQU  $3F2                     Soft RESET vector
  44.  
  45. VECTIN      GEQU  $BE32                    BASIC.SYSTEM input vector
  46. GETBUF      GEQU  $BEF5                    Allocate buffer space
  47. FREEBUF    GEQU  $BEF8                    Free up buffer space
  48.  
  49. INLIN        GEQU  $D52C                    Input a line of text
  50. FIXUP        GEQU  $D539                    Fixup for tokenizer
  51. PARSE        GEQU  $D559                    Tokenize input buffer
  52. KEYCHR      GEQU  $D72C                    Get a keyword char
  53. ADDON        GEQU  $D998                    Add Y to text pointer
  54. PRINT        GEQU  $DAD5                    PRINT command action
  55. CRDO          GEQU  $DAFB                    Print out a CR
  56. STROUT      GEQU  $DB3A                    Output a string
  57. OUTSP        GEQU  $DB57                    Print out a space
  58. OUTDO        GEQU  $DB5C                    Print out a char
  59. FRMEVL      GEQU  $DD7B                    Evaluate expression
  60. INPRT        GEQU  $ED19                    Print IN (current line)
  61. LINPRT      GEQU  $ED20                    Print the line number
  62. PRDEC        GEQU  $ED24                    Print a number X/A
  63.  
  64. SETTXT      GEQU  $FB39                    Set text screen mode
  65. TABV          GEQU  $FB5B                    Set a vertical tab
  66. SETPWRC    GEQU  $FB6F                    Set powerup checksum
  67. HOME          GEQU  $FC58                    Clear the screen
  68. CLREOP      GEQU  $FC42                    Clear to end of page
  69. WAIT          GEQU  $FCA8                    Time delay routine
  70. RDKEY        GEQU  $FD0C                    Read a keypress
  71. KEYIN        GEQU  $FD1B                    Read the keyboard
  72. GETLIN      GEQU  $FD6F                    Get a line of text
  73. COUT1        GEQU  $FDF0                    Char output routine
  74. MOVE          GEQU  $FE2C                    Move a block of memory
  75. SETINV      GEQU  $FE80                    Set INVERSE video
  76. SETNORM    GEQU  $FE84                    Set NORMAL video mode
  77. SETKBD      GEQU  $FE89                    Set normal KSW vector
  78. SETVID      GEQU  $FE93                    Set 40-column video
  79. BELL          GEQU  $FF3A                    Sound the error bell
  80. RESTORE    GEQU  $FF3F                    Restore registers
  81. STORE        GEQU  $FF4A                    Store registers
  82.  
  83. ****************************************************************
  84. *
  85. *        Super TRACE installation routine
  86. *
  87. ****************************************************************
  88. *
  89.  
  90.                   JSR   SETTXT                   Set text screen
  91.                   JSR   HOME                     Clear the screen
  92.                   LDA   #CREDITS                 Setup so STROUT will
  93.                   LDY   #>CREDITS
  94.                   JSR   STROUT                   Print the credits
  95.                   LDX   #SUPER                   Get the starting address
  96.                   LDA   #>SUPER                  of the main program code
  97.                   STX   MOVST                    Setup the start of block
  98.                   STA   MOVST+1                  to move parameter
  99.                   LDX   #END                     Get the ending address
  100.                   LDA   #>END                    of the main program
  101.                   STX   MOVEND                   Setup the end of block
  102.                   STA   MOVEND+1                 to move parameter
  103.                   LDX   #KBDIN                   Get the destination address
  104.                   LDA   #>KBDIN                  of the main program code
  105.                   STX   MOVDST                   Setup the destination
  106.                   STA   MOVDST+1                 address parameter
  107.                   LDY   #$00                     Zero Y for MOVE call
  108.                   JSR   MOVE                     Move Super TRACE into place
  109.                   STY   TVAR                     No trace variable
  110.                   JSR   PATCH                    Patch CHRGET routine
  111.                   LDX   #RESET                   Get the address of the
  112.                   LDA   #>RESET                  Control RESET trap
  113.                   STX   SOFTEV                   Setup the system
  114.                   STA   SOFTEV+1                 RESET vector
  115.                   JSR   SETPWRC                  Validate the vector change
  116.                   LDX   #KBDIN                   Get the address of the
  117.                   LDA   #>KBDIN                  keyboard intecepter
  118.                   STX   KSW                      Setup the zero page
  119.                   STA   KSW+1                    input vector address
  120.                   LDY   $BF00                    Check the DOS
  121.                   CPY   #$4C                     $BF00=$4C if ProDOS
  122.                   BNE   INSTALL1                 No ProDOS, DOS 3.3
  123.                   STX   VECTIN                   Tell BASIC.SYSTEM where
  124.                   STA   VECTIN+1                 our input routine is
  125.                   JSR   FREEBUF                  Freeup buffer space
  126.                   LDA   #$0D                     Ask BASIC.SYSTEM for
  127.                   JSR   GETBUF                   13 memory pages
  128.                   JMP   WARMST                   Exit to Applesoft
  129. INSTALL1  STX   HIMEM                    Lower HIMEM to protect
  130.                   STA   HIMEM+1                  the program from BASIC
  131.                   JSR   DOSHOOK                  Hookup DOS
  132.                   JMP   WARMST
  133. CREDITS    DC    H'0D0A',C'SUPER TRACE BY GARY ASH',H'0D0A'
  134.                   DC    C'(C) 1991 MINDCRAFT PUBL. CORP.',H'8D8A00'
  135.  
  136. ****************************************************************
  137. *
  138. *        SuperTRACE main program code
  139. *
  140. ****************************************************************
  141. *
  142. SUPER        ANOP
  143.                   OBJ   $8D00                    Main program's origin
  144. ****************************************************************
  145. *
  146. *        Keyboard intercepter routine
  147. *
  148. ****************************************************************
  149. *
  150. KBDIN        ANOP
  151.                   STY   TEMP                     Save Y register
  152.                   JSR   KEYIN                    Read a keypress
  153.                   LDY   PROMPT                   See if system is in
  154.                   CPY   #']'+$80                 Applesoft direct mode
  155.                   BEQ   KBDIN2                   Yep, check for command
  156. KBDIN1      LDY   TEMP                     Restore Y register
  157.                   RTS                            Exit with keypress
  158. KBDIN2      LDY   #$05                     There are 6 commands
  159. KBDIN3      CMP   CMDSTBL,Y                This loop compares the
  160.                   BEQ   KBDIN4                   keypress against a table
  161.                   DEY                            of SUPERTRACE commands
  162.                   BPL   KBDIN3                   Check against whole table
  163.                   BMI   KBDIN1                   Keypress isn't a command
  164. KBDIN4      TYA                            This stuff computes the
  165.                   ASL   A                        index into the command
  166.                   TAY                            handler address table
  167.                   LDA   ADRTBL+1,Y               Get the handler's address
  168.                   PHA                            and push it on the stack
  169.                   LDA   ADRTBL,Y                 so we can use an RTS instr
  170.                   PHA                            to make the call (Fake a
  171.                   RTS                            return from subroutine)
  172.  
  173. ****************************************************************
  174. *
  175. *        Control RESET trapping routine
  176. *
  177. ****************************************************************
  178. *
  179. RESET        ANOP
  180.                   JSR   CRDO                     Makes screen prettier
  181.                   JSR   PATCH                    Make sure CHRGET is patched
  182.                   LDX   #KBDIN                   Get the address of the
  183.                   LDA   #>KBDIN                  keyboard intercepter
  184.                   STX   KSW                      Make sure we're hooked
  185.                   STA   KSW+1                    into the I/O loop
  186.                   JMP   WARMST                   WARMST makes vector stick
  187.  
  188. ****************************************************************
  189. *
  190. *        Program execution monitor routine
  191. *
  192. ****************************************************************
  193. *
  194. MONIT        JSR   STORE                    Save the registers
  195.                   LDA   TXTPTR+1                 Is a program executing?
  196.                   CMP   #$08                     Yes, if TXTPTR=> then $08
  197.                   BCS   MONIT3                   Program is running
  198.                   LDA   CURLIN                   Update LASTLN variable
  199.                   STA   LASTLN
  200.                   LDA   CURLIN+1
  201.                   STA   LASTLN+1
  202. MONIT1      INC   TXTPTR                   Point TXTPTR to the
  203.                   BNE   MONIT2                   next program char
  204.                   INC   TXTPTR+1
  205. MONIT2      JSR   RESTORE                  Restore entry registers
  206.                   JMP   REENTRY                  Re-enter CHRGET code
  207. MONIT3      LDX   #$00                     Save the current
  208. MONIT4      LDA   $00,X                    zero page values
  209.                   STA   ZPAGE,X                  in their own buffer
  210.                   INX                            to prevent the
  211.                   BNE   MONIT4                   BASIC program from
  212. !                                               being bombed out
  213.                   LDY   #39                      Save bottom line of
  214. SAVLOOP    LDA   $7D0,Y                   the screen in a special
  215.                   STA   LINEBUF,Y                buffer
  216.                   DEY                            Screen column number-1
  217.                   BPL   SAVLOOP                  Done yet? No
  218.                   JSR   UNPATCH                  Restore a normal CHRGET
  219.                   JSR   SETNORM                  Set NORMAL screen mode
  220.                   LDA   #$01                     Applesoft outputing
  221.                   STA   SPDBYTE                  at SPEED=255
  222.                   LDA   #COUT1                   Disconnect DOS output
  223.                   STA   CSW                      vector we can trace
  224.                   LDA   #>COUT1                  through a DOS command's
  225.                   STA   CSW+1                    execution
  226.                   LDA   #23                      Tab the cursor down
  227.                   JSR   TABV                     down to line 23
  228.                   LDA   #$00
  229.                   STA   CH                       column 0
  230.                   JSR   CLREOP                   Clear the line
  231.                          ;
  232.                          ;  Check conditional trap points
  233.                          ;
  234. CHKCON      LDY   #$05                     Start with last trap
  235. CHKCON1    LDA   CFLAG,Y                  Get trap's status flag
  236.                   BEQ   CHKCON2                  0=Trap not set, 1=Active trap
  237.                   STY   TRAP                     Save trap number
  238.                   JSR   CALCADR                  Calc. buffer address
  239.                   JSR   FRMEVL                   Evaluate conditional
  240.                   LDA   FAC                      And the results are...
  241.                   BNE   CONTRAP                  the trap was sprung
  242.                   LDY   TRAP                     False condition
  243. CHKCON2    DEY                            try next trap
  244.                   BPL   CHKCON1                  End of traps list? No
  245.                          ;
  246.                          ;  Check unconditional trap points
  247.                          ;
  248.                   LDY   #$05                     Start with last trap
  249. CHKUNC      LDA   UNFLAG,Y                 Get trap's status
  250.                   BEQ   CHKUNC1                  Skip inactive traps
  251.                   LDA   CURLIN                   Use a 16-bit comparison
  252.                   CMP   TRAPLO,Y                 to see if we should be
  253.                   LDA   CURLIN+1                 stopping the program
  254.                   SBC   TRAPHI,Y
  255.                   BEQ   UNCTRAP                  Yes, trap this line
  256. CHKUNC1    DEY                            Trap number-1
  257.                   BPL   CHKUNC                   Done checking? No
  258.                          ;
  259.                          ;  Check for a trace variable
  260.                          ;
  261.                   LDA   TVAR                     Is there a variable?
  262.                   BEQ   PRLINE                   No, check conditional
  263.                   LDA   #CRSUP                   Install a CR suppressor
  264.                   STA   CSW                      output intercept
  265.                   LDA   #>CRSUP
  266.                   STA   CSW+1
  267.                   LDA   #VARBUF                  Point AppleSoft's
  268.                   STA   TXTPTR                   text pointer at
  269.                   LDY   #>VARBUF                 variable storage
  270.                   STY   TXTPTR+1                 buffer
  271.                   JSR   STROUT                   Print the name
  272.                   LDA   #'='                     Print an =
  273.                   JSR   OUTDO
  274.                   JSR   PRINT                    Print the value
  275.                   LDA   #COUT1                   Reconnect the COUT1
  276.                   STA   CSW                      output vector
  277.                   LDA   #>COUT1
  278.                   STA   CSW+1
  279.                   JSR   INPRT                    Tell line number
  280.                   JSR   PATCH                    Restore patch is CHRGET
  281.                          ;
  282.                          ;  Print the line number
  283.                          ;
  284. PRLINE      LDA   TVAR                     Do we need to?
  285.                   BNE   EXIT                     No, just exit
  286.                   JSR   LINPRT                   Print the line #
  287. EXIT          LDX   #$12                     Delay routine
  288. EXIT1        LDY   #$FF
  289. EXIT2        DEY
  290.                   BNE   EXIT2
  291.                   DEX
  292.                   BPL   EXIT1
  293.                   LDY   #39                      Restore the bottom line
  294. RESLOOP    LDA   LINEBUF,Y
  295.                   STA   $7D0,Y
  296.                   DEY                            Loop counter-1
  297.                   BPL   RESLOOP                  Done yet? No
  298.                   LDX   #$00                     Restore the zero
  299. EXIT4        LDA   ZPAGE,X                  page values
  300.                   STA   $00,X
  301.                   INX
  302.                   BNE   EXIT4
  303.                   JMP   MONIT1                   Exit the monitor
  304.                          ;
  305.                          ;  Do a conditional trap
  306.                          ;
  307. CONTRAP    JSR   PRNTCON                  Print the condition
  308.                   JMP   LEAVE                    and exit to AppleSoft
  309.                          ;
  310.                          ;  Do an unconditional trap
  311.                          ;
  312. UNCTRAP    LDA   #TRAPPED                 Print out the
  313.                   LDY   #>TRAPPED                TRAPPED message
  314.                   JSR   STROUT
  315. LEAVE        JSR   INPRT                    Tell line # of trap
  316.                   JSR   BELL                     Sound the error tone
  317.                   JMP   RESET                    Exit to Applesoft
  318.                          ;
  319.                          ;  CR suppressor routine
  320.                          ;
  321. CRSUP        CMP   #$8D                     CR going out?
  322.                   BEQ   CRSUP2                   Yes
  323.                   STY   YREG                     Save (Y)
  324.                   LDY   CH                       Check cursor position
  325.                   CPY   #30                      Column 30 yet?
  326.                   BCS   CRSUP1                   Yes, truncate the output
  327.                   LDY   YREG                     Restore (Y)
  328.                   JMP   COUT1                    Output anything but CR
  329. CRSUP1      LDY   YREG
  330.                   JSR   SETINV                   Set inverse video
  331. CRSUP2      RTS                            Igore the CR
  332.  
  333. ****************************************************************
  334. *
  335. *        Disconnect Super TRACE
  336. *
  337. ****************************************************************
  338. *
  339. DISCON      JSR   UNPATCH                  Restore CHRGET code
  340.                   JSR   SETKBD                   Unhook input routine
  341.                   LDX   WARMST+1                 This stuff will
  342.                   LDA   WARMST+2                 disconnect the
  343.                   STX   SOFTEV                   Control RESET
  344.                   STA   SOFTEV+1                 trap routine
  345.                   JSR   SETPWRC                  Validate vector change
  346.                   LDA   $BF00                    Check for ProDOS again
  347.                   CMP   #$4C                     (INSTALL has comments)
  348.                   BNE   DISCON1
  349.                   JSR   FREEBUF                  Restore HIMEM
  350.                   JMP   DISCON2                  Go wave good-bye
  351. DISCON1    LDA   #$00                     Restore the normal
  352.                   STA   HIMEM                    (boot up) HIMEM
  353.                   LDA   #$96                     address. (38400)
  354.                   STA   HIMEM+1
  355. DISCON2    LDA   #BYE                     Setup to print out
  356.                   LDY   #>BYE                    "GOODBYE"
  357.                   JSR   STROUT                   Print it
  358.                   JMP   WARMST                   Exit
  359.  
  360. ****************************************************************
  361. *
  362. *  Set a conditional trap point
  363. *
  364. ****************************************************************
  365. *
  366. SETCON      LDY   #$00                     This loop will try to
  367. SETCON1    LDA   CFLAG,Y                  find an open conditional
  368.                   BEQ   SETCON2                  trap buffer -- Found
  369.                   INY                            Check next trap
  370.                   CPY   #$06                     Checked all traps?
  371.                   BNE   SETCON1                  Nope, not yet
  372.                   BEQ   FULL                     Yep, buffers are full
  373. SETCON2    STY   TRAP                     Save the trap number
  374. SETCON3    JSR   CRDO                     Neaten things up
  375.                   LDA   #CONDIT                  Ask the user for the
  376.                   LDY   #>CONDIT                 trap condition
  377.                   JSR   STROUT                   Print the string
  378.                   JSR   INLIN                    Get the input
  379.                   LDA   INBUF                    Check for null input
  380.                   BEQ   DONE
  381.                   JSR   TXTBUF                   Position text pointer
  382.                   JSR   PARSE                    Tokenize the input
  383.                   CPY   #19+5                    Condition too long?
  384.                   BCS   SETCON3                  Yep, re-prompt user
  385.                   LDY   #$00                     This loop check for
  386.                   STY   TEMP                     TEMP is token flag
  387. SETCON4    LDA   INBUF,Y                  validate condition
  388.                   BEQ   SETCON6                  entry. Invalidate
  389.                   BMI   SETCON9                  Token found
  390. SETCON5    INY                            Next char
  391.                   BNE   SETCON4                  Always taken
  392. SETCON6    LDA   TEMP                     TEMP is token found flag
  393.                   BEQ   SETCON3                  Invalidate entry made
  394.                   JSR   CALCADR                  Calc. buffer address
  395.                   LDY   #$00                     This loop stores the
  396. SETCON7    LDA   INBUF,Y                  in its buffer area
  397.                   STA   (MOVDST),Y
  398.                   BEQ   SETCON8                  $00 when done storing
  399.                   INY                            Kick up index
  400.                   BNE   SETCON7                  Always taken
  401. SETCON8    LDY   TRAP                     Get trap number
  402.                   LDA   #$01                     Mark trap as "USED"
  403.                   STA   CFLAG,Y
  404.                   BNE   DONE                     We're all done
  405. SETCON9    CMP   #$C2                     FN token is valid
  406.                   BEQ   SETCON10                 Go set flag
  407.                   CMP   #$C6                     NOT token is valid
  408.                   BEQ   SETCON10                 Set the token flag
  409.                   CMP   #$C8                     This stuff will handle
  410.                   BCC   SETCON3                  a block of validate tokens
  411. SETCON10  LDA   #$01                     Set token flag
  412.                   STA   TEMP
  413.                   BNE   SETCON5                  Continue checking entry
  414.  
  415. ****************************************************************
  416. *
  417. *        Set an unconditional trap point
  418. *
  419. ****************************************************************
  420. *
  421. SETUNC      LDY   #$00                     This loop will try to
  422. SETUNC1    LDA   UNFLAG,Y                 find an open unconditional
  423.                   BEQ   SETUNC2                  trap buffer -- Found
  424.                   INY                            Check next trap
  425.                   CPY   #$06                     Checked all traps?
  426.                   BNE   SETUNC1                  Nope, not yet
  427. FULL          LDA   #TBFULL                  Setup to print out
  428.                   LDY   #>TBFULL                 "TRAP BUFFERS FULL"
  429.                   JSR   STROUT                   Print the message
  430.                   JMP   RESET                    Exit
  431. SETUNC2    STY   TRAP                     Save the trap number
  432. SETUNC3    LDA   #LINE                    Setup to print out
  433.                   LDY   #>LINE                   "LINE TO TRAP?"
  434.                   JSR   STROUT                   Print the prompt
  435.                   JSR   CONVERT                  Get and convert input
  436.                   BCS   SETUNC3                  Carry set if input error
  437.                   LDY   TRAP                     Restore trap number
  438.                   LDA   MOVEND                   Save the line number
  439.                   STA   TRAPLO,Y                 in the unconditional
  440.                   LDA   MOVEND+1                 trap buffer
  441.                   STA   TRAPHI,Y
  442.                   LDA   #$01                     Mark trap as "USED"
  443.                   STA   UNFLAG,Y
  444. DONE          JMP   RESET                    Exit via RESET handler
  445.  
  446. ****************************************************************
  447. *
  448. *        Remove unconditional trap
  449. *
  450. ****************************************************************
  451. *
  452. REMOVUN    JSR   CRDO                     Print a CR
  453.                   LDX   #$00                     This loop will print
  454. REMOVUN1  LDA   UNFLAG,X                 out all the active
  455.                   BEQ   REMOVUN2                 traps. Skip--inactive
  456.                   STX   TRAP                     Save trap number
  457.                   LDA   #$00                     Setup code -- PRDEC
  458.                   JSR   PRDEC                    Print trap number
  459.                   LDA   #'.'                     Print out a '.'
  460.                   JSR   OUTDO
  461.                   LDA   #$05                     Set an HTAB of 6
  462.                   STA   CH
  463.                   LDY   TRAP                     Get trap number
  464.                   LDX   TRAPLO,Y                 Get trap value
  465.                   LDA   TRAPHI,Y
  466.                   JSR   PRDEC                    Print the trap value
  467.                   JSR   CRDO                     Print a CR
  468.                   LDX   TRAP                     Get trap number
  469. REMOVUN2  INX                            Bump it up
  470.                   CPX   #$06                     Done printing?
  471.                   BNE   REMOVUN1                 Branch if not
  472. REMOVUN3  LDA   #REMOVE                  Ask the user for
  473.                   LDY   #>REMOVE                 number of trap
  474.                   JSR   STROUT                   to be removed
  475.                   JSR   CONVERT                  Get/convert input
  476.                   BCS   REMOVUN3                 Conversion error
  477.                   LDA   MOVEND                   Check for a validate
  478.                   CMP   #$06                     input range (0-6)
  479.                   LDA   MOVEND+1                 with a 16-bit compare
  480.                   SBC   #$00
  481.                   BCS   REMOVUN3                 Bad input made
  482.                   LDX   MOVEND                   Clear the trap
  483.                   LDA   #$00                     $00 is UNFLAG means
  484.                   STA   UNFLAG,X                 trap is inactive
  485. DONE2        JMP   RESET                    Exit, we're done
  486.  
  487. ****************************************************************
  488. *
  489. *        Remove condional trap
  490. *
  491. ****************************************************************
  492. *
  493. REMOVCN    JSR   CRDO                     Print a CR
  494.                   LDX   #$00                     This loop will print
  495. REMOVCN1  LDA   CFLAG,X                  out all the active
  496.                   BEQ   REMOVCN2                 traps. Skip--inactive
  497.                   STX   TRAP                     Save trap number
  498.                   LDA   #$00                     Setup code -- PRDEC
  499.                   JSR   PRDEC                    Print trap number
  500.                   LDA   #'.'                     Print out a '.'
  501.                   JSR   OUTDO
  502.                   LDY   #$05                     Set an HTAB of 6
  503.                   STY   CH
  504.                   JSR   CALCADR                  Calc. buffer address
  505.                   JSR   PRNTCON                  Print the condition
  506.                   JSR   CRDO                     Print a CR
  507.                   LDX   TRAP                     Get trap number
  508. REMOVCN2  INX                            Bump it up
  509.                   CPX   #$06                     Done printing?
  510.                   BNE   REMOVCN1                 Branch if not
  511. REMOVCN3  LDA   #REMOVE                  Ask the user for
  512.                   LDY   #>REMOVE                 number of trap
  513.                   JSR   STROUT                   to be removed
  514.                   JSR   CONVERT                  Get/convert input
  515.                   BCS   REMOVCN3                 Conversion error
  516.                   LDA   MOVEND                   Check for a validate
  517.                   CMP   #$06                     input range (0-6)
  518.                   LDA   MOVEND+1                 with a 16-bit compare
  519.                   SBC   #$00
  520.                   BCS   REMOVCN3                 Bad input made
  521.                   LDX   MOVEND                   Clear the trap
  522.                   LDA   #$00                     $00 is CFLAG means
  523.                   STA   CFLAG,X                  trap is inactive
  524.                   BEQ   DONE2                    Exit, we're done
  525. ****************************************************************
  526. *
  527. *        Enter a trace variable
  528. *
  529. ****************************************************************
  530. *
  531. TRACE        LDA   #VARNAM                  Ask for the trace
  532.                   LDY   #>VARNAM                 variable name
  533.                   JSR   STROUT                   Print the prompt
  534.                   JSR   GETLIN                   Get the input
  535.                   CPX   #$07                     Is name too big?
  536.                   BCS   TRACE                    Yep, re-prompt
  537.                   CPX   #$00                     Null entry made?
  538.                   BEQ   TRACE6                   Branch if yes
  539.                   JSR   FIXUP                    Fixup for parser
  540.                   JSR   TXTBUF                   Position text pointer
  541.                   JSR   PARSE                    Parse the input
  542.                   LDY   #$00                     This loop checks to
  543. TRACE1      LDA   INBUF,Y                  be sure the user
  544.                   BEQ   TRACE2                   didn't type in a
  545.                   BMI   TRACE                    invalidate name
  546.                   INY                            Bump the index
  547.                   BNE   TRACE1                   Always taken
  548. TRACE2      LDY   #$00                     This loop copies
  549. TRACE3      LDA   INBUF,Y                  the name into
  550.                   STA   VARBUF,Y                 its buffer
  551.                   BEQ   TRACE4                   $00 when done
  552.                   INY                            Bump the index
  553.                   BNE   TRACE3                   Always taken
  554. TRACE4      LDA   #$01                     Trace variable on
  555. TRACE5      STA   TVAR
  556.                   JMP   RESET                    Exit
  557. TRACE6      LDA   #ONOFFTXT                Ask user:
  558.                   LDY   #>ONOFFTXT               "VARIABLE (O)N OR O(F)F?"
  559.                   JSR   STROUT                   Print prompt
  560.                   JSR   RDKEY                    Get input
  561.                   AND   #$DF                     Adjust the case
  562.                   CMP   #'O'+$80                 'O' means on
  563.                   BEQ   TRACE4
  564.                   CMP   #'F'+$80                 'F' means oFf
  565.                   BNE   TRACE6                   Branch if bad input
  566.                   LDA   #$00                     Variable off
  567.                   BEQ   TRACE5
  568. ****************************************************************
  569. *
  570. *        Subroutines begin here
  571. *
  572. ****************************************************************
  573. *
  574.                          ;
  575.                          ; Position text pointer to input buffer
  576.                          ;
  577. TXTBUF      LDA   #INBUF
  578.                   STA   TXTPTR
  579.                   LDA   #>INBUF
  580.                   STA   TXTPTR+1
  581.                   RTS
  582.                          ;
  583.                          ; Convert a decimal number
  584.                          ;
  585.                          ; This routine was based on
  586.                          ; DOS 3.3 base converison
  587.                          ; routine - Disassembled
  588.                          ; in Nibble vol 4/Num 5
  589.                          ;
  590. CONVERT    JSR   GETLIN                   Get the input
  591.                   CPX   #$00                     Null input made?
  592.                   BNE   CONVERT0                 Nope, continue
  593.                   JMP   RESET                    Exit via RESET
  594. CONVERT0  LDX   #$00                     (X) is now $00
  595.                   STX   MOVEND                   Clear the number hold
  596.                   STX   MOVEND+1
  597.                   STX   MOVDST                   Clear INBUF index
  598. CONVERT1  JSR   CONVERT5                 Get a digit from INBUF
  599.                   BEQ   CONVERT3                 Exit if zero bit on
  600.                   SEC                            Do validity check
  601.                   SBC   #$B0                     ASCII to hex digit
  602.                   BMI   CONVERT2                 Error if digit<0
  603.                   CMP   #$0A                     Digit greater then 9?
  604.                   BCS   CONVERT2                 Branch if error
  605.                   JSR   CONVERT4                 Digit * 2
  606.                   ADC   MOVEND                   dd digit to MOVEND
  607.                   TAX                            X=MOVEND+1 + digit
  608.                   LDA   #$00                     Do high byte of addition
  609.                   ADC   MOVEND+1                 Handles any carries
  610.                   TAY                            Y=MOVEND+1 * 2
  611.                   JSR   CONVERT4                 MOVEND+1 * 4
  612.                   JSR   CONVERT4                 MOVEND+1 * 8
  613.                   TXA
  614.                   ADC   MOVEND                   Add up MOVEND * 2 + digit
  615.                   STA   MOVEND
  616.                   TYA
  617.                   ADC   MOVEND+1                 Add MOVEND+1 * 2
  618.                   STA   MOVEND+1
  619.                   BCC   CONVERT1                 Continue conversion
  620. CONVERT2  SEC                            Set carry flags an error
  621.                   RTS                            Exit if conversion error
  622. CONVERT3  CLC                            No error in conversion
  623.                   RTS                            Exit cleanly
  624. CONVERT4  ASL   MOVEND                   MOVEND * 2 (16-bit)
  625.                   ROL   MOVEND+1
  626.                   RTS
  627. CONVERT5  LDX   MOVDST                   Get input buffer index
  628.                   LDA   INBUF,X                  Get a digit
  629.                   CMP   #$8D                     Check for CR
  630.                   BEQ   CONVERT3                 Exit if CR
  631.                   INX                            Bump line index
  632.                   STX   MOVDST                   Store the index
  633.                   RTS                            Exit CONVERT
  634.                          ;
  635.                          ; Calcualate the address of a
  636.                          ; conditional trap buffer
  637.                          ;
  638. CALCADR    LDA   #CONBUF                  Point the text pointer
  639.                   STA   TXTPTR                   at the start of the
  640.                   LDA   #>CONBUF                 conditional buffers
  641.                   STA   TXTPTR+1
  642.                   LDX   TRAP                     Get trap number in X
  643. CALCADR1  DEX                            Trap number - 1
  644.                   BMI   CALCADR2                 Branch when done
  645.                   LDY   #20                      Add 20 to address
  646.                   JSR   ADDON                    (Stored in TXTPTR)
  647.                   JMP   CALCADR1                 Go to top of loop
  648. CALCADR2  LDA   TXTPTR                   Save the address
  649.                   STA   MOVDST                   also in MOVDST
  650.                   LDA   TXTPTR+1
  651.                   STA   MOVDST+1
  652.                   RTS
  653.                          ;
  654.                          ; Print a conditional
  655.                          ;
  656.                          ; Based on the Applesoft
  657.                          ; LIST command handler -
  658.                          ; Disassembled in Nibble
  659.                          ; vol 4/num 4
  660.                          ;
  661. PRNTCON    LDY   #$00                     Zero the data index
  662. PRNTCON1  LDA   (MOVDST),Y               Get byte from condition
  663.                   BMI   PRNTCON3                 Branch if a token value
  664.                   BEQ   PRNTCON9                 Exit on $00 byte
  665.                   JSR   OUTDO                    Print ASCII char
  666. PRNTCON2  INY                            Bump the data index
  667.                   BNE   PRNTCON1                 Always taken
  668. PRNTCON3  STY   TEMP                     Save Y's value
  669.                   LDY   #$D0                     Setup the keyword
  670.                   STY   DSCTMP                   table pointer to
  671.                   DEY                            $CFD0. Y=$CF
  672.                   STY   DSCTMP+1
  673.                   LDY   #$FF                     Set char index
  674.                   SEC                            Trim token to keyword
  675.                   SBC   #$7F                     number (1=END...127=MID$)
  676.                   TAX                            Move number to X
  677. PRNTCON4  DEX                            Table number - 1
  678.                   BEQ   PRNTCON6                 Branch when found
  679. PRNTCON5  JSR   KEYCHR                   This loop will skip
  680.                   BPL   PRNTCON5                 the unwanted keywords
  681.                   BMI   PRNTCON4                 Last char of word is ASCII
  682. PRNTCON6  JSR   OUTSP                    Print a leading space
  683. PRNTCON7  JSR   KEYCHR                   Get keyword char
  684.                   BMI   PRNTCON8                 Branch if last letter
  685.                   JSR   OUTDO                    Print non final letter
  686.                   BNE   PRNTCON7                 Continue printing word
  687. PRNTCON8  JSR   OUTDO                    Print last letter
  688.                   LDY   TEMP                     Restore index
  689.                   JSR   OUTSP                    Print a trailing space
  690.                   BNE   PRNTCON2                 Continue with line
  691. PRNTCON9  RTS                            Exit
  692.                          ;
  693.                          ; Patch the CHRGET routine
  694.                          ;
  695. PATCH        ENTRY                          Define the entry point
  696.                   LDA   #$4C                     Put a JMP in the
  697.                   STA   POINT                    CHRGET subroutine
  698.                   LDA   #MONIT                   the execution monitor
  699.                   STA   POINT+1                  will be called by
  700.                   LDA   #>MONIT                  Applesoft
  701.                   STA   POINT+2
  702.                   RTS
  703.                          ;
  704.                          ; Unpatch the CHRGET routine
  705.                          ;
  706. UNPATCH    LDA   #$E6                     $E6 is INC opcode
  707.                   STA   POINT                    Put it back in CHRGET
  708.                   LDA   #TXTPTR                  Operand of INC opcode
  709.                   STA   POINT+1
  710.                   LDA   #$D0                     $D0 is BNE opcode
  711.                   STA   POINT+2
  712.                   RTS
  713.                          ;
  714.                          ; Program data storage area
  715.                          ;
  716.                          ;
  717.                          ; Super TRACE commands table
  718.                          ;                ^D^O^N
  719. CMDSTBL    DC    H'848F8E'
  720.                          ;                ^R^S^T
  721.                   DC    H'929394'
  722.                          ;
  723.                          ; Command handler jump table
  724.                          ;
  725. ADRTBL      DC    A'DISCON-1'
  726.                   DC    A'SETCON-1'
  727.                   DC    A'SETUNC-1'
  728.                   DC    A'REMOVUN-1'
  729.                   DC    A'REMOVCN-1'
  730.                   DC    A'TRACE-1'
  731.                          ;
  732.                          ; Program's textual data
  733.                          ;
  734. CONDIT      DC    C'CONDITION:',H'00'
  735. TRAPPED    DC    C'TRAPPED',H'00'
  736. BYE            DC    H'8D',C'GOODBYE',H'8D00'
  737. LINE          DC    H'8D',C'LINE TO TRAP?',H'00'
  738. VARNAM      DC    H'8D',C'VARIABLE NAME?',H'00'
  739. ONOFFTXT  DC    C'VARIABLE (O)N OR O(F)F?',H'00'
  740. REMOVE      DC    H'8D',C'TRAP TO REMOVE?',H'00'
  741. TBFULL      DC    H'8D',C'TRAP BUFFERS FULL',H'878D00'
  742.                          ;
  743.                          ; Program's data buffers
  744.                          ;
  745.                          ;
  746. LINEBUF    DS    40                       Screen line buffer
  747. CFLAG        DS    6                        Status of conditional traps
  748. UNFLAG      DS    6                        Status of unconditional traps
  749. TRAPLO      DS    6                        Trapped line number low byte
  750. TRAPHI      DS    6                        Trapped line number high byte
  751. VARBUF      DS    9                        Trace variable name storage
  752. CONBUF      DS    20*6                     Conditional trap buffer
  753. ZPAGE        DS    256                      Zero page storage buffer
  754.                   OBJEND                         End of main program
  755. END            ANOP
  756. MAIN          END                            End of source code
  757.